<template>
	<view class="PT_2">
		<view class="bg_fff P_1 PLR_2 flex_row_around MLR_2 B_radius_5 flex_rowL">
			<view class="">
				<view class="WH_2vw B_radius_circle pub_bg">
					
				</view>
				<view class="color_gray" style="width: 1px;padding-left: 0.5vw;margin-top: -8px;">
					<view style="height: 6px;" class="">
						.
					</view>
					<view style="height: 6px;" class="">
						.
					</view>
					<view style="height: 6px;" class="">
						.
					</view>
				</view>
				<view class="WH_2vw B_radius_circle color_bgdown MT_3">
					
				</view>
			</view>
			
			<view class="flex_flex1 PL_2">
				<view @click="tabChange" class="flex_row_between line_bom PTB_2">
					<view class="">
						从
					</view>
					<view class="">
						{{firCode.toUpperCase()}}
					</view>
					<image class="W_4vw" src="../../static/goyou.png" mode="widthFix"></image>
				</view>
				<view @click="tabChange" class="flex_row_between PTB_2">
					<view class="">
						从
					</view>
					<view class="">
						{{secCode.toUpperCase()}}
					</view>
					<image class="W_4vw" src="../../static/goyou.png" mode="widthFix"></image>
				</view>
			</view>
			
			<!-- <view @click="tabChange('ksa')" :class="type=='ksa'?'color_red':''">
				USDT转KSA
			</view>
			<view @click="tabChange('usdt')" :class="type=='usdt'?'color_red':''">
				KSA转USDT
			</view> -->
		</view>
		<view class="bg_fff B_radius_5 P_2 M_2 PTB_3">
			<view class="flex_rowL ">
				<view class="PR_2 font_weight_bold fontS_16">
					划转数量
				</view>
				<view class="color_gray PL_1">
					(1USDT≈{{Number(rate).toFixed(2)}}KSA)
				</view>
			</view>
			<view class="line_bom flex_row_between">
				<!-- <view class="flex_rowL PTB_3 line_bom">
					<view class="PR_2">
						对方手机号码：
					</view>
					<input v-model="another" placeholder="请输入对方手机号码" type="text" />
				</view> -->
				
				<view class="flex_rowL PTB_2">
					
					<!-- <dropdown :current="cnum" :list="list" @onClick="dropDownChange" /> -->
					<input class="fontS_14 W_30vw" v-model="money" placeholder="请输入数量" type="number" />
				</view>
				
				<view class="flex_rowL">
					<view class="color_gray">
						{{firCode.toUpperCase()}}
					</view>
					<view class="MLR_1 H_4vw bg_gray" style="width: 1px;">
						
					</view>
					<view @click="allNum" class="pub_color">
						全部
					</view>
				</view>
				
			</view>
			<view class="PT_1 color_gray flex_row_between">
				<view class="">
					可用：{{Number(num).toFixed(2)}}{{firCode.toUpperCase()}}
				</view>
				<view v-if="firCode=='usdt'">
					预计可兑：{{(money*rate).toFixed(2)}}KSA
				</view>
				<view v-else>
					预计可兑：{{(money/rate).toFixed(2)}}USDT
				</view>
			</view>
		</view>
		
		
		<view class="PTB_3 flex_rowC PT_8">
			<view @click="saleIt" 
			class="pub_bg color_fff PTB_2 flex_rowC PLR_30 B_radius_max">
				闪兑
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="W_60vw bg_fff B_radius_5">
				<view class="flex_rowC PTB_4">
					支付密码
				</view>
				<view class="PTB_1 MLR_5 flex_rowC MB_3 B_radius_5" style="border: 1px solid #C7C7C7;">
					<input class="textC" v-model="pass" type="number" value="" />
				</view>
				<view class="flex_row_between" style="border-top: 1px solid #cecece">
				  <view
					@click="canclePop"
					class="flex_rowC PTB_3"
					style="width: 50%; border-right: 1px solid #cecece"
				  >
					取消
				  </view>
				  <view @click="saleIt" style="width: 50%" class="flex_rowC color_red">
					确认
				  </view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				type:'ksa',
				pass:'',
				another:'',
				money:'',
				cnum:0,
				firCode:'usdt',
				secCode:'ksa',
				ksa:'',
				usdt:'',
				num:'',
				rate:''
			}
		},
		onLoad() {
			//this.getList()
			this.getSort();
			this.getRate()
		},
		onShow() {
			this.getSort();
			this.getRate()
		},
		methods: {
			getRate(){
				let _this = this;
				this.$req('index/getRate',{},function(res){
					_this.rate = res.data.rate
					//console.log(res)
				})
			},
			allNum(){
				this.money = this.num;
			},
			getSort(){
				let _this = this;
				this.$req('account/index',{},function(res){
					let list = res.data;
					list.forEach((item)=>{
						if(item.currency_name=='KSA'){
							_this.ksa = item;
							// _this.ksas = item.currency
						}
						if(item.currency_name=='USDT'){
							_this.usdt = item;
							// _this.usdt = item.currency
						}
						if(_this.firCode == 'ksa'){
							_this.num = _this.ksa.money
						}else{
							_this.num = _this.usdt.money
						}
					})
				})
			},
			canclePop() {
			  this.pass = "";
			  this.$refs.popup.close();
			},
			getPop() {
			  if(!this.money){
				  this.toast('请输入划转数量');
			  }else{
				  this.$refs.popup.open()
			  }
			  
			},
			saleIt() {
				let _this = this;
				if(!this.money){
					this.toast('请输入闪兑数量')
				}else{
					this.$req('account/transfer',{
						type:_this.firCode,
						// mobile:_this.another,
						money:_this.money,
						// paypwd:_this.pass
					},function(res){
						if(res.code==1){
							// _this.$refs.popup.close();
							_this.getSort()
							_this.money = ''
						}
						_this.toast(res.msg)
					})
				}
			},
			tabChange(){
				let _this = this;
				if(this.firCode == 'usdt'){
					this.firCode = 'ksa';
					this.secCode = 'usdt';
					_this.num = _this.ksa.money
				}else{
					this.firCode = 'usdt';
					this.secCode = 'ksa';
					_this.num = _this.usdt.money
				};
				console.log(this.firCode + ':' + this.num)
			},
			getList(){
				let _this = this;
				this.$req('user/getAmountOption',{},function(res){
					if(res.code==1){
						_this.list = res.data;
						// _this.money = _this.list[0];
					}else{
						_this.toast(res.msg)
					}
				})
			},
			dropDownChange(i){
				this.money = this.list[i];
				this.cnum = i;
				console.log(this.money)
			}
		}
	}
</script>

<style>
.line_bom{
	border-bottom: 1px solid #C7C7C7;
}
</style>
